package com.hhc.controller;

import com.hhc.dto.NoticeDTO;
import com.hhc.query.NoticeQuery;
import com.hhc.service.NoticeService;
import com.hhc.utils.RestResult;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *   通知公告控制器
 * </p>
 * @author pc
 */
@RestController
@RequestMapping("/notice")
@RequiredArgsConstructor
public class NoticeController {

    private final NoticeService noticeService;

    /**
     * 发布通知公告
     *
     * @param noticeDTO 公告信息
     * @return RestResult
     */
    @PostMapping("/publish")
    public RestResult<String> publish(@Valid @RequestBody NoticeDTO noticeDTO) {
        return noticeService.publish(noticeDTO);
    }

    /**
     * 查询通知公告列表
     *
     * @param query 查询参数
     * @return RestResult
     */
    @GetMapping("/list")
    public RestResult<Object> list(@Valid NoticeQuery query) {
        return noticeService.list(query);
    }

    /**
     * 获取通知公告详情
     *
     * @param id 公告ID
     * @return RestResult
     */
    @GetMapping("/{id}")
    public RestResult<Object> detail(@PathVariable Long id) {
        return noticeService.detail(id);
    }

    /**
     * 更新通知公告
     *
     * @param id 公告ID
     * @param noticeDTO 更新信息
     * @return RestResult
     */
    @PutMapping("/{id}")
    public RestResult<String> update(@PathVariable Long id, @Valid @RequestBody NoticeDTO noticeDTO) {
        return noticeService.update(id, noticeDTO);
    }

    /**
     * 删除通知公告
     *
     * @param id 公告ID
     * @return RestResult
     */
    @DeleteMapping("/{id}")
    public RestResult<String> delete(@PathVariable Long id) {
        return noticeService.delete(id);
    }
}